home *** CD-ROM | disk | FTP | other *** search
/ PC Advisor 2011 May / PC Advisor 190 E.iso / pc / ESSENTIALS / VLC Media Player 1.1 / vlc-1.1.5-win32.exe / lua / playlist / jamendo.lua < prev    next >
Encoding:
Text File  |  2010-11-13  |  3.0 KB  |  66 lines

  1. --[[
  2.  $Id$
  3.  
  4.  Copyright ┬⌐ 2010 VideoLAN and AUTHORS
  5.  
  6.  Authors: Fabio Ritrovato <sephiroth87 at videolan dot org>
  7.  
  8.  This program is free software; you can redistribute it and/or modify
  9.  it under the terms of the GNU General Public License as published by
  10.  the Free Software Foundation; either version 2 of the License, or
  11.  (at your option) any later version.
  12.  
  13.  This program is distributed in the hope that it will be useful,
  14.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  GNU General Public License for more details.
  17.  
  18.  You should have received a copy of the GNU General Public License
  19.  along with this program; if not, write to the Free Software
  20.  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  21. --]]
  22.  
  23. require "simplexml"
  24.  
  25. -- Probe function.
  26. function probe()
  27.     return vlc.access == "http"
  28.         and string.match( vlc.path, "jamendo.com/get2/" )
  29.         and string.match( vlc.path, "/track/xml/" )
  30. end
  31.  
  32. -- Parse function.
  33. function parse()
  34.     local page = ""
  35.     while true do
  36.         local line = vlc.readline()
  37.         if line == nil then break end
  38.         page = page .. line
  39.     end
  40.     local tracks = {}
  41.     local tree = simplexml.parse_string( page )
  42.     for _, track in ipairs( tree.children ) do
  43.         simplexml.add_name_maps( track )
  44.         if track.children_map["id"] == nil and
  45.            track.children_map["stream"] == nil then
  46.             vlc.msg.err( "No track id or stream URL, not enough info to add tracks..." )
  47.             return {}
  48.         end
  49.         local stream_url
  50.         if track.children_map["id"][1].children[1] then
  51.             stream_url = "http://api.jamendo.com/get2/stream/track/redirect/?id=" .. track.children_map["id"][1].children[1]
  52.         else
  53.             stream_url = track.children_map["stream"][1].children[1]
  54.         end
  55.         table.insert( tracks, {path=stream_url,
  56.                                arturl=track.children_map["album_image"] and track.children_map["album_image"][1].children[1] or ( track.children_map["album_id"] and "http://imgjam.com/albums/".. track.children_map["album_id"][1].children[1] .. "/covers/1.500.jpg" or nil ),
  57.                                title=track.children_map["name"] and track.children_map["name"][1].children[1] or nil,
  58.                                artist=track.children_map["artist_name"] and track.children_map["artist_name"][1].children[1] or nil,
  59.                                album=track.children_map["album_name"] and track.children_map["album_name"][1].children[1] or nil,
  60.                                genre=track.children_map["album_genre"] and track.children_map["album_genre"][1].children[1] or nil,
  61.                                duration=track.children_map["duration"] and track.children_map["duration"][1].children[1] or nil,
  62.                                date=track.children_map["album_dates"] and track.children_map["album_dates"][1].children_map["year"][1].children[1] or nil} )
  63.     end
  64.     return tracks
  65. end
  66.